package logic

import (
	"context"
	"fmt"
	"house/models/mysql"
	"strings"

	"house/houserpc/houserpc"
	"house/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AskAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAskAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AskAddLogic {
	return &AskAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AskAddLogic) AskAdd(in *houserpc.AskAddRequest) (*houserpc.AskAddResponse, error) {
	// todo: add your logic here and delete this line
	var ask = mysql.Ask{
		UserId:  int(in.UserId),
		HouseId: int(in.HouseId),
		Content: in.Content,
	}
	if strings.Contains(in.Content, "中介费") || strings.Contains(in.Content, "虚假") {
		return nil, fmt.Errorf("当前问题不符合社区规范,请修改后重新提交")
	}
	mysql.DB.Debug().Create(&ask)
	return &houserpc.AskAddResponse{
		AskId: int64(ask.ID),
	}, nil
}
